﻿@model FreightSoft.Models.SHIPMENT

@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{
    FreightSoft.Models.Entities db = new FreightSoft.Models.Entities();
    FreightSoft.Models.SHIPMENT shipment = db.SHIPMENTs.Find(@Model.SHIPMENTID);    
}

<h2>Shipment Details - @Model.SHIPMENTID</h2>

<br />
<p style="float:right">



    @if (shipment.STATUS.Equals("Released"))
    { 
        <a href="../Plan/@shipment.SHIPMENTID"><button type="button" class="btn btn-primary" style="width: 100px">Plan</button></a>
    }

    @if (shipment.STATUS.Equals("Planned"))
    {
        if (shipment.SHIPMENTLINEs != null)
        {
            if (shipment.SHIPMENTLINEs.Count() > 0)
            {
            <a href="../Release/@shipment.SHIPMENTID">
                <button type="button" class="btn btn-success" style="width: 100px">Release</button></a>
            }
        }
    }

    @if (shipment.STATUS.Equals("Planned") || shipment.STATUS.Equals("Released") || shipment.STATUS.Equals("Authorized"))
    {
            <a href="../Cancel/@shipment.SHIPMENTID"><button type="button" class="btn btn-info" style="width: 100px">Cancel</button></a>
    }

    @if (shipment.STATUS.Equals("Cancelled"))
    {
        <a href="../Plan/@shipment.SHIPMENTID"><button type="button" class="btn btn-info" style="width: 100px">Re-Open</button></a>
    }

    @if (shipment.STATUS.Equals("Released"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
        <a href="../Authorize/@shipment.SHIPMENTID">
            <button type="button" class="btn btn-warning" style="width: 100px">Authorize</button></a> 
        }
    }

    @if (shipment.STATUS.Equals("Authorized"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
            <a href="../Plan/@shipment.SHIPMENTID"><button type="button" class="btn btn-warning">Revoke Authorization</button></a>
        }
    }
    @if (shipment.STATUS.Equals("InTransit"))
    {
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
            <a href="../Deliver/@shipment.SHIPMENTID"><button type="button" class="btn btn-warning">Deliver</button></a>
        }
    }
     @if (shipment.STATUS.Equals("Delivered"))
    {
        
         
        if (User.IsInRole("SHIPAUTH") || User.IsInRole("ORDAUTH"))
        {
            
         <!-- Single button -->
    <div class="btn-group">
      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        Reports <span class="caret"></span>
      </button>
      <ul class="dropdown-menu" role="menu">
        <li><a href="../ShipmentDelNote/@shipment.SHIPMENTID">Shipment Delivery Note</a></li>
        
      </ul>
    </div>
         
        }
    }


</p>

<table class="table">
     <tr>
        <td colspan="4">
            @if (TempData["error"] != null)
            {
                <div class="alert alert-danger">@TempData["error"]</div>
            }
        </td>
    </tr>
    <tr class="active"><td><b>Shipment Id</b></td><td><b>Planned Start Date</b></td><td><b>Planned Delivery Date</b></td></tr>
    <tr class="active"><td>@shipment.SHIPMENTID</td><td>@shipment.PLANNED_START_DATE</td><td>@shipment.PLANNED_DELIVERY_DATE</td></tr>
    <tr class="active"><td><b>Starting Port</b></td><td><b>Final Port</b></td><td><b>Status</b></td></tr>
    <tr class="active"><td>@Model.ORIGINPORT</td><td>@Model.DESTINATIONPORT</td><td>@shipment.STATUS</td></tr>
    <tr class="active"><td><b>Total Weight (kg)</b></td><td><b>Total Volume (m3)</b></td><td></td></tr>
    <tr class="active"><td>@shipment.WEIGHT</td><td>@shipment.VOLUME</td><td></td></tr>
    <tr class="active"><td></td><td></td><td></td></tr>
</table>
<br />


@if (shipment.STATUS.Equals("Planned"))
 {
    @*<a href="../AddOrders?PostData1=@shipment.SHIPMENTID"><button type="button" class="btn btn-info" style="width: 150px">Add Orders</button></a>*@
     @*<button type="button" class="btn btn-primary" style="width: 100px">@Html.ActionLink("Add Shipment Lines", "AddOrders", "Shipment", new { shipment_id =  @shipment.SHIPMENTID}, null)</button>*@
     @Html.ActionLink("Add Orders", "AddOrders", "Shipment", new { shipment_id =  @shipment.SHIPMENTID}, null)
 }
@*<a href="../ViewOrders/@shipment.SHIPMENTID"><button type="button" class="btn btn-info" style="width: 100px">View Orders</button></a>*@

<br />


<table class="table table-striped">
    <tr>
       <th>
            @Html.DisplayNameFor(model => model.SHIPMENTLINEs.ElementAt(0).SHIPMENTLINENO)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.SHIPMENTLINEs.ElementAt(0).ORDERID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.SHIPMENTLINEs.ElementAt(0).CUSTOMERID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.VOLUME)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.WEIGHT)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.STATUS)
        </th>
    </tr>

@foreach (var item in Model.SHIPMENTLINEs) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.SHIPMENTLINENO)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ORDERID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.CUSTOMERID)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.VOLUME)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.WEIGHT)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.STATUS)
        </td>

        <td>
             @if (shipment.STATUS.Equals("Planned") || shipment.STATUS.Equals("Docked"))
 {
             @Html.ActionLink("Remove", "RemoveOrder", "ShipmentLine", new { shipment_id = @shipment.SHIPMENTID, order_id =item.ORDERID }, null)
             }
            @*@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new {  id=item.SHIPMENTID,   }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })*@
        </td>
    </tr>
}
    </table>

<p>
   @* @Html.ActionLink("Edit", "Edit", new { id=Model.SHIPMENTID }) |*@
    @Html.ActionLink("Back to List", "Index")
</p>
